package com.ruoyi.employee_info.service.impl;

import java.util.List;
import java.util.Random;

import cn.hutool.Hutool;
import cn.hutool.core.util.RandomUtil;
import com.ruoyi.common.core.domain.model.RegisterBody;
import com.ruoyi.employee_info.domain.ro.LoginRo;
import com.ruoyi.framework.web.service.SysRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.employee_info.mapper.SillEmployeeMapper;
import com.ruoyi.employee_info.domain.SillEmployee;
import com.ruoyi.employee_info.service.ISillEmployeeService;

/**
 * 员工信息表Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-08-09
 */
@Service
public class SillEmployeeServiceImpl implements ISillEmployeeService 
{
    @Autowired
    private SillEmployeeMapper sillEmployeeMapper;

    @Autowired
    private SysRegisterService sysRegisterService;

    /**
     * 查询员工信息表
     * 
     * @param id 员工信息表主键
     * @return 员工信息表
     */
    @Override
    public SillEmployee selectSillEmployeeById(Long id)
    {
        return sillEmployeeMapper.selectSillEmployeeById(id);
    }

    /**
     * 查询员工信息表列表
     * 
     * @param sillEmployee 员工信息表
     * @return 员工信息表
     */
    @Override
    public List<SillEmployee> selectSillEmployeeList(SillEmployee sillEmployee)
    {
        return sillEmployeeMapper.selectSillEmployeeList(sillEmployee);
    }

    /**
     * 新增员工信息表
     * 
     * @param sillEmployee 员工信息表
     * @return 结果
     */
    @Override
    public int insertSillEmployee(SillEmployee sillEmployee)
    {
        Random random = new Random();
        int randomNumber = random.nextInt();
        sillEmployee.setEmployeeNum("IT"+"-"+randomNumber);

        RegisterBody registerBody = new RegisterBody();
        registerBody.setUsername(sillEmployee.getEmployeeNum());
        registerBody.setPassword("123456");
       sysRegisterService.register(registerBody);
        return sillEmployeeMapper.insertSillEmployee(sillEmployee);
    }


    /**
     * 修改员工信息表
     * 
     * @param sillEmployee 员工信息表
     * @return 结果
     */
    @Override
    public int updateSillEmployee(SillEmployee sillEmployee)
    {
        return sillEmployeeMapper.updateSillEmployee(sillEmployee);
    }

    /**
     * 批量删除员工信息表
     * 
     * @param ids 需要删除的员工信息表主键
     * @return 结果
     */
    @Override
    public int deleteSillEmployeeByIds(Long[] ids)
    {
        Long id = ids[0];
        String employeeNum = sillEmployeeMapper.selectNum(id);
        sillEmployeeMapper.deleteUser(employeeNum);
        return sillEmployeeMapper.deleteSillEmployeeByIds(ids);
    }

    /**
     * 删除员工信息表信息
     * 
     * @param id 员工信息表主键
     * @return 结果
     */
    @Override
    public int deleteSillEmployeeById(Long id)
    {
        /*String employeeNum = sillEmployeeMapper.selectNum(id);
        sillEmployeeMapper.deleteUser(employeeNum);*/
        return sillEmployeeMapper.deleteSillEmployeeById(id);
    }
}
